Skip to content

perf(flow-chat): improve long session readiness#1134

Merged
limityan merged 1 commit into
GCWing:mainfrom
limityan:yanzhn/perf-startup-p0-p1
Jun 10, 2026
Merged

perf(flow-chat): improve long session readiness#1134
limityan merged 1 commit into
GCWing:mainfrom
limityan:yanzhn/perf-startup-p0-p1

Conversation

@limityan

@limityan limityan commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Defer restored historical-session background command snapshots until the latest restored content is visible, so non-critical session metadata work does not compete with the first readable frame.
  • Delay activity touch for metadata-only historical sessions until hydration completes and the target session actually switches, avoiding stale side work during rapid switching.
  • Expand the initial render window only when the latest restored turn is user-only, preserving recent context without applying a global extra-turn DOM cost.
  • Tighten the performance E2E workspace setup and add a clearer rapid-switch breakdown for target-click, latest-visible, latest-usable, and per-session trace phases.

Performance Data

Measured on release-fast builds, 5 runs each, same generated long-session fixture. Baseline is latest GCWing/BitFun main at bc3e5f33; this PR is 5fb8184.

Scenario Baseline median PR median Delta Delta % Baseline min-max PR min-max Visual guard
Startup interactive shell ready 764.8 ms 768.9 ms +4.1 ms +0.5% 751.6-944.8 732.7-882.6 startup guardrail only
Long session first open latest usable 285.4 ms 279.0 ms -6.4 ms -2.2% 268.6-369.8 259.4-294.7 no loading/blank/scroll/non-target events
Long session warm reopen latest usable 177.7 ms 169.6 ms -8.1 ms -4.6% 164.0-226.0 161.8-194.7 no loading/blank/scroll/non-target events
Rapid switch target latest usable 958.0 ms 865.0 ms -93.0 ms -9.7% 900.4-1184.9 818.7-914.1 no loading/blank/scroll/non-target events

Startup is included only as a guardrail. The measured +4.1 ms startup delta is within run-to-run noise and this PR should not be interpreted as a startup optimization.

Rapid-Switch Breakdown

Diagnostic sample from the latest PR run, measured from the first click in a rapid A -> B -> C session switch sequence:

Segment Duration
First click -> target session click 409.8 ms
Target click -> latest content visible 374.4 ms
Latest visible -> latest usable viewport 59.4 ms
Target click -> latest usable viewport 433.8 ms

Per-session trace sample from that run:

Session Click offset Hydrate start Hydrate end Restore duration State commit Latest frame
A 33.4 ms 74.2 ms 161.3 ms 85.8 ms 0.5 ms 277.7 ms
B 188.5 ms 128.8 ms 226.6 ms 95.7 ms 1.0 ms 346.1 ms
C target 409.8 ms 193.3 ms 262.4 ms 67.3 ms 0.5 ms 403.5 ms

Risks and Guardrails

  • Background command activity can appear slightly later on restored historical sessions, but live command events remain the source of truth and the snapshot still runs once latest content is visible.
  • User-only latest turns render one extra previous turn during initial history paint; the extra DOM cost is conditional and the rapid-switch E2E path remains faster than baseline.
  • Activity touch is no longer sent for a superseded metadata-only switch. This avoids stale recency updates during rapid switch, but failed or superseded opens also stop updating recency.
  • Rapid-switch breakdown is test/report-only. It does not add production instrumentation or runtime logs; the console summary uses compact relative timings.
  • The perf E2E helper opt-out only applies to this perf spec; default workspace tests still require nav label visibility.

Verification

  • Rebased onto latest GCWing/BitFun main at bc3e5f33
  • pnpm --dir src/web-ui run test:run src/flow_chat/components/modern/VirtualMessageList.layout.test.ts src/flow_chat/components/modern/ModernFlowChatContainer.history-state.test.tsx src/flow_chat/services/flow-chat-manager/SessionModule.test.ts (51 tests passed)
  • pnpm run lint:web (0 errors; existing warning in untouched FlowChatManager.ts)
  • pnpm run check:repo-hygiene
  • git diff --check gcwing/main..HEAD
  • pnpm run desktop:build:release-fast for baseline and PR builds
  • pnpm --dir tests/e2e run test:perf x5 for latest main baseline and x5 for this PR

@limityan limityan force-pushed the yanzhn/perf-startup-p0-p1 branch from 9d4fc44 to 5fb8184 Compare June 10, 2026 08:16
@limityan limityan marked this pull request as ready for review June 10, 2026 08:16
@limityan limityan merged commit f13283e into GCWing:main Jun 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant